﻿/*
Copyright (c) 2005-2008, CellAO Team

All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

    * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
    * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
    * Neither the name of the CellAO Team nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

using System;
using System.Collections.Generic;
using AO.Core;

namespace ZoneEngine
{
    /// <summary>
    /// 
    /// </summary>
    class StatTypes
    {
        #region Constructors

        /// <summary>
        /// 
        /// </summary>
        /// <param name="statId"></param>
        /// <param name="statName"></param>
        public StatTypes(int statId, string statName)
        {
            this.statId = statId;
            this.statName = statName;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="statId"></param>
        /// <param name="statName"></param>
        /// <param name="defaultValue"></param>
        public StatTypes(int statId, string statName, int defaultValue)
            : this(statId, statName)
        {
            this.defaultValue = defaultValue;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="statId"></param>
        /// <param name="statName"></param>
        /// <param name="statFullName"></param>
        public StatTypes(int statId, string statName, string statFullName)
            : this(statId, statName)
        {
            this.statFullName = statFullName;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="statId"></param>
        /// <param name="statName"></param>
        /// <param name="defaultValue"></param>
        /// <param name="statFullName"></param>
        public StatTypes(int statId, string statName, int defaultValue, string statFullName)
            : this(statId, statName, statFullName)
        {
            this.defaultValue = defaultValue;
        }

        #endregion

        public int statId;

        public string statName;

        public string statFullName = string.Empty;

        public int defaultValue = 1234567890;
    }

    /// <summary>
    /// 
    /// </summary>
    static class StatsList
    {
        #region Stats List

        public static readonly List<StatTypes> stats = new List<StatTypes>
        {
            new StatTypes(0, "Flags", 8917569),
            new StatTypes(1, "Life", 1),
            new StatTypes(2, "VolumeMass"),
            new StatTypes(3, "AttackSpeed", 5),
            new StatTypes(4, "Breed"),
            new StatTypes(5, "Clan", 0),
            new StatTypes(6, "Team", 0),
            new StatTypes(7, "State", 0),
            new StatTypes(8, "TimeExist"),
            new StatTypes(9, "MapFlags", 0),
            new StatTypes(10, "ProfessionLevel"),
            new StatTypes(11, "PreviousHealth", 50),
            new StatTypes(12, "Mesh", 17530),
            new StatTypes(13, "Anim"),
            new StatTypes(14, "Name"),
            new StatTypes(15, "Info"),
            new StatTypes(16, "Strength", 0),
            new StatTypes(17, "Agility", 0),
            new StatTypes(18, "Stamina", 0),
            new StatTypes(19, "Intelligence", 0),
            new StatTypes(20, "Sense", 0),
            new StatTypes(21, "Psychic", 0),
            new StatTypes(22, "AMS"),
            new StatTypes(23, "StaticInstance"),
            new StatTypes(24, "MaxMass"),
            new StatTypes(25, "StaticType"),
            new StatTypes(26, "Energy"),
            new StatTypes(27, "Health", 50),
            new StatTypes(28, "Height"),
            new StatTypes(29, "DMS"),
            new StatTypes(30, "Can"),
            new StatTypes(31, "Face"),
            new StatTypes(32, "HairMesh", 0),
            new StatTypes(33, "Side", 0),
            new StatTypes(34, "DeadTimer", 0),
            new StatTypes(35, "AccessCount"),
            new StatTypes(36, "AttackCount"),
            new StatTypes(37, "TitleLevel", 1),
            new StatTypes(38, "BackMesh"),
            new StatTypes(39, "ShoulderMesh"),
            new StatTypes(40, "AlienXP", 0),
            new StatTypes(41, "FabricType"),
            new StatTypes(42, "CATMesh"),
            new StatTypes(43, "ParentType"),
            new StatTypes(44, "ParentInstance"),
            new StatTypes(45, "BeltSlots", 0),
            new StatTypes(46, "BandolierSlots"),
            new StatTypes(47, "Fatness"),
            new StatTypes(48, "ClanLevel"),
            new StatTypes(49, "InsuranceTime", 0),
            new StatTypes(50, "InventoryTimeout"),
            new StatTypes(51, "AggDef", 100),
            new StatTypes(52, "XP", 0),
            new StatTypes(53, "IP", 1500),
            new StatTypes(54, "Level"),
            new StatTypes(55, "InventoryId"),
            new StatTypes(56, "TimeSinceCreation"),
            new StatTypes(57, "LastXP", 0),
            new StatTypes(58, "Age", 0),
            new StatTypes(59, "Sex"),
            new StatTypes(60, "Profession"),
            new StatTypes(61, "Cash", 0),
            new StatTypes(62, "Alignment", 0), // Clan Tokens
            new StatTypes(63, "Attitude", 0),
            new StatTypes(64, "HeadMesh"),
            new StatTypes(65, "MissionBits5", 0),
            new StatTypes(66, "MissionBits6", 0),
            new StatTypes(67, "MissionBits7", 0),
            new StatTypes(68, "VeteranPoints", 0),
            new StatTypes(69, "MonthsPaid", 0),
            new StatTypes(70, "SpeedPenalty"),
            new StatTypes(71, "TotalMass"),
            new StatTypes(72, "ItemType", 0),
            new StatTypes(73, "RepairDifficulty"),
            new StatTypes(74, "Price"),
            new StatTypes(75, "MetaType", 0), // Omni-Tek Tokens
            new StatTypes(76, "ItemClass"),
            new StatTypes(77, "RepairSkill"),
            new StatTypes(78, "CurrentMass", 0),
            new StatTypes(79, "Icon", 0),
            new StatTypes(80, "PrimaryItemType"),
            new StatTypes(81, "PrimaryItemInstance"),
            new StatTypes(82, "SecondaryItemType"),
            new StatTypes(83, "SecondaryItemInstance"),
            new StatTypes(84, "UserType"),
            new StatTypes(85, "UserInstance"),
            new StatTypes(86, "AreaType"),
            new StatTypes(87, "AreaInstance"),
            new StatTypes(88, "DefaultPos"),
            new StatTypes(89, "Race", 1),
            new StatTypes(90, "ProjectileAC", 0),
            new StatTypes(91, "MeleeAC", 0),
            new StatTypes(92, "EnergyAC", 0),
            new StatTypes(93, "ChemicalAC", 0),
            new StatTypes(94, "RadiationAC", 0),
            new StatTypes(95, "ColdAC", 0),
            new StatTypes(96, "PoisonAC", 0),
            new StatTypes(97, "FireAC", 0),
            new StatTypes(98, "StateAction"),
            new StatTypes(99, "ItemAnim"),
            new StatTypes(100, "MartialArts", 5),
            new StatTypes(101, "MeleeMultiple", 5),
            new StatTypes(102, "1hBluntWeapons", 5),
            new StatTypes(103, "1hEdgedWeapon", 5),
            new StatTypes(104, "MeleeEnergyWeapon", 5),
            new StatTypes(105, "2hEdgedWeapons", 5),
            new StatTypes(106, "Piercing", 5),
            new StatTypes(107, "2hBluntWeapons", 5),
            new StatTypes(108, "ThrowingKnife", 5),
            new StatTypes(109, "Grenade", 5),
            new StatTypes(110, "ThrownGrapplingWeapons", 5),
            new StatTypes(111, "Bow", 5),
            new StatTypes(112, "Pistol", 5),
            new StatTypes(113, "Rifle", 5),
            new StatTypes(114, "SubMachineGun", 5),
            new StatTypes(115, "Shotgun", 5),
            new StatTypes(116, "AssaultRifle", 5),
            new StatTypes(117, "DriveWater", 5),
            new StatTypes(118, "CloseCombatInitiative", 5),
            new StatTypes(119, "DistanceWeaponInitiative", 5),
            new StatTypes(120, "PhysicalProwessInitiative", 5),
            new StatTypes(121, "BowSpecialAttack", 5),
            new StatTypes(122, "SenseImprovement", 5),
            new StatTypes(123, "FirstAid", 5),
            new StatTypes(124, "Treatment", 5),
            new StatTypes(125, "MechanicalEngineering", 5),
            new StatTypes(126, "ElectricalEngineering", 5),
            new StatTypes(127, "MaterialMetamorphose", 5),
            new StatTypes(128, "BiologicalMetamorphose", 5),
            new StatTypes(129, "PsychologicalModification", 5),
            new StatTypes(130, "MaterialCreation", 5),
            new StatTypes(131, "MaterialLocation", 5),
            new StatTypes(132, "NanoEnergyPool", 5),
            new StatTypes(133, "LR_EnergyWeapon", 5), // Note, this must keep the LR_ prefix for in-game client compatability of named stats
            new StatTypes(134, "LR_MultipleWeapon", 5), // As above
            new StatTypes(135, "DisarmTrap", 5),
            new StatTypes(136, "Perception", 5),
            new StatTypes(137, "Adventuring", 5),
            new StatTypes(138, "Swim", 5),
            new StatTypes(139, "DriveAir", 5),
            new StatTypes(140, "MapNavigation", 5),
            new StatTypes(141, "Tutoring", 5),
            new StatTypes(142, "Brawl", 5),
            new StatTypes(143, "Riposte", 5),
            new StatTypes(144, "Dimach", 5),
            new StatTypes(145, "Parry", 5),
            new StatTypes(146, "SneakAttack", 5),
            new StatTypes(147, "FastAttack", 5),
            new StatTypes(148, "Burst", 5),
            new StatTypes(149, "NanoProwessInitiative", 5),
            new StatTypes(150, "FlingShot", 5),
            new StatTypes(151, "AimedShot", 5),
            new StatTypes(152, "BodyDevelopment", 5),
            new StatTypes(153, "Duck", 5),
            new StatTypes(154, "Dodge", 5),
            new StatTypes(155, "Evade", 5),
            new StatTypes(156, "RunSpeed", 5),
            new StatTypes(157, "FieldQuantumPhysics", 5),
            new StatTypes(158, "WeaponSmithing", 5),
            new StatTypes(159, "Pharmaceuticals", 5),
            new StatTypes(160, "NanoProgramming", 5),
            new StatTypes(161, "ComputerLiteracy", 5),
            new StatTypes(162, "Psychology", 5),
            new StatTypes(163, "Chemistry", 5),
            new StatTypes(164, "Concealment", 5),
            new StatTypes(165, "BreakingEntry", 5),
            new StatTypes(166, "DriveGround", 5),
            new StatTypes(167, "FullAuto", 5),
            new StatTypes(168, "NanoAC", 5),
            new StatTypes(169, "AlienLevel", 0),
            new StatTypes(170, "HealthChangeBest"),
            new StatTypes(171, "HealthChangeWorst"),
            new StatTypes(172, "HealthChange"),
            new StatTypes(173, "CurrentMovementMode", 3),
            new StatTypes(174, "PrevMovementMode", 3),
            new StatTypes(175, "AutoLockTimeDefault"),
            new StatTypes(176, "AutoUnlockTimeDefault"),
            new StatTypes(177, "MoreFlags"),
            new StatTypes(178, "AlienNextXP", 1500),
            new StatTypes(179, "NPCFlags"),
            new StatTypes(180, "CurrentNCU", 0),
            new StatTypes(181, "MaxNCU", 8),
            new StatTypes(182, "Specialization", 0),
            new StatTypes(183, "EffectIcon"),
            new StatTypes(184, "BuildingType"),
            new StatTypes(185, "BuildingInstance"),
            new StatTypes(186, "CardOwnerType"),
            new StatTypes(187, "CardOwnerInstance"),
            new StatTypes(188, "BuildingComplexInst"),
            new StatTypes(189, "ExitInstance"),
            new StatTypes(190, "NextDoorInBuilding"),
            new StatTypes(191, "LastConcretePlayfieldInstance", 0),
            new StatTypes(192, "ExtenalPlayfieldInstance"),
            new StatTypes(193, "ExtenalDoorInstance"),
            new StatTypes(194, "InPlay", 0),
            new StatTypes(195, "AccessKey"),
            new StatTypes(196, "PetMaster"),
            new StatTypes(197, "OrientationMode"),
            new StatTypes(198, "SessionTime"),
            new StatTypes(199, "RP", 0),
            new StatTypes(200, "Conformity"),
            new StatTypes(201, "Aggressiveness"),
            new StatTypes(202, "Stability"),
            new StatTypes(203, "Extroverty"),
            new StatTypes(204, "BreedHostility"),
            new StatTypes(205, "ReflectProjectileAC", 0),
            new StatTypes(206, "ReflectMeleeAC", 0),
            new StatTypes(207, "ReflectEnergyAC", 0),
            new StatTypes(208, "ReflectChemicalAC", 0),
            new StatTypes(209, "WeaponMesh"),
            new StatTypes(210, "RechargeDelay"),
            new StatTypes(211, "EquipDelay"),
            new StatTypes(212, "MaxEnergy"),
            new StatTypes(213, "TeamSide", 0),
            new StatTypes(214, "CurrentNano", 1),
            new StatTypes(215, "GmLevel", 0),
            new StatTypes(216, "ReflectRadiationAC", 0),
            new StatTypes(217, "ReflectColdAC", 0),
            new StatTypes(218, "ReflectNanoAC", 0),
            new StatTypes(219, "ReflectFireAC", 0),
            new StatTypes(220, "CurrBodyLocation", 0),
            new StatTypes(221, "MaxNanoEnergy", 1),
            new StatTypes(222, "AccumulatedDamage"),
            new StatTypes(223, "CanChangeClothes"),
            new StatTypes(224, "Features", 6),
            new StatTypes(225, "ReflectPoisonAC", 0),
            new StatTypes(226, "ShieldProjectileAC", 0),
            new StatTypes(227, "ShieldMeleeAC", 0),
            new StatTypes(228, "ShieldEnergyAC", 0),
            new StatTypes(229, "ShieldChemicalAC", 0),
            new StatTypes(230, "ShieldRadiationAC", 0),
            new StatTypes(231, "ShieldColdAC", 0),
            new StatTypes(232, "ShieldNanoAC", 0),
            new StatTypes(233, "ShieldFireAC", 0),
            new StatTypes(234, "ShieldPoisonAC", 0),
            new StatTypes(235, "BerserkMode"),
            new StatTypes(236, "InsurancePercentage", 0),
            new StatTypes(237, "ChangeSideCount", 0),
            new StatTypes(238, "AbsorbProjectileAC", 0),
            new StatTypes(239, "AbsorbMeleeAC", 0),
            new StatTypes(240, "AbsorbEnergyAC", 0),
            new StatTypes(241, "AbsorbChemicalAC", 0),
            new StatTypes(242, "AbsorbRadiationAC", 0),
            new StatTypes(243, "AbsorbColdAC", 0),
            new StatTypes(244, "AbsorbFireAC", 0),
            new StatTypes(245, "AbsorbPoisonAC", 0),
            new StatTypes(246, "AbsorbNanoAC", 0),
            new StatTypes(247, "TemporarySkillReduction", 0),
            new StatTypes(248, "BirthDate"),
            new StatTypes(249, "LastSaved"),
            new StatTypes(250, "SoundVolume"),
            new StatTypes(251, "PetCounter"),
            new StatTypes(252, "MeetersWalked"),
            new StatTypes(253, "QuestLevelsSolved"),
            new StatTypes(254, "MonsterLevelsKilled"),
            new StatTypes(255, "PvPLevelsKilled"),
            new StatTypes(256, "MissionBits1", 0),
            new StatTypes(257, "MissionBits2", 0),
            new StatTypes(258, "AccessGrant"),
            new StatTypes(259, "DoorFlags"),
            new StatTypes(260, "ClanHierarchy"),
            new StatTypes(261, "QuestStat"),
            new StatTypes(262, "ClientActivated"),
            new StatTypes(263, "PersonalResearchLevel", 0),
            new StatTypes(264, "GlobalResearchLevel", 0),
            new StatTypes(265, "PersonalResearchGoal", 0),
            new StatTypes(266, "GlobalResearchGoal", 0),
            new StatTypes(267, "TurnSpeed", 40000),
            new StatTypes(268, "LiquidType"),
            new StatTypes(269, "GatherSound"),
            new StatTypes(270, "CastSound"),
            new StatTypes(271, "TravelSound"),
            new StatTypes(272, "HitSound"),
            new StatTypes(273, "SecondaryItemTemplate"),
            new StatTypes(274, "EquippedWeapons"),
            new StatTypes(275, "XPKillRange", 5),
            new StatTypes(276, "AMSModifier", 0),
            new StatTypes(277, "DMSModifier", 0),
            new StatTypes(278, "ProjectileDamageModifier", 0),
            new StatTypes(279, "MeleeDamageModifier", 0),
            new StatTypes(280, "EnergyDamageModifier", 0),
            new StatTypes(281, "ChemicalDamageModifier", 0),
            new StatTypes(282, "RadiationDamageModifier", 0),
            new StatTypes(283, "ItemHateValue"),
            new StatTypes(284, "DamageBonus"),
            new StatTypes(285, "MaxDamage"),
            new StatTypes(286, "MinDamage"),
            new StatTypes(287, "AttackRange"),
            new StatTypes(288, "HateValueModifyer"),
            new StatTypes(289, "TrapDifficulty"),
            new StatTypes(290, "StatOne"),
            new StatTypes(291, "NumAttackEffects"),
            new StatTypes(292, "DefaultAttackType"),
            new StatTypes(293, "ItemSkill"),
            new StatTypes(294, "ItemDelay"),
            new StatTypes(295, "ItemOpposedSkill"),
            new StatTypes(296, "ItemSIS"),
            new StatTypes(297, "InteractionRadius"),
            new StatTypes(298, "Placement"),
            new StatTypes(299, "LockDifficulty"),
            new StatTypes(300, "Members", 999),
            new StatTypes(301, "MinMembers"),
            new StatTypes(302, "ClanPrice"),
            new StatTypes(303, "MissionBits3", 0),
            new StatTypes(304, "ClanType"),
            new StatTypes(305, "ClanInstance"),
            new StatTypes(306, "VoteCount"),
            new StatTypes(307, "MemberType"),
            new StatTypes(308, "MemberInstance"),
            new StatTypes(309, "GlobalClanType"),
            new StatTypes(310, "GlobalClanInstance"),
            new StatTypes(311, "ColdDamageModifier"),
            new StatTypes(312, "ClanUpkeepInterval"),
            new StatTypes(313, "TimeSinceUpkeep"),
            new StatTypes(314, "ClanFinalized"),
            new StatTypes(315, "NanoDamageModifier", 0),
            new StatTypes(316, "FireDamageModifier", 0),
            new StatTypes(317, "PoisonDamageModifier", 0),
            new StatTypes(318, "NPCostModifier", 0),
            new StatTypes(319, "XPModifier", 0),
            new StatTypes(320, "BreedLimit"),
            new StatTypes(321, "GenderLimit"),
            new StatTypes(322, "LevelLimit"),
            new StatTypes(323, "PlayerKilling"),
            new StatTypes(324, "TeamAllowed"),
            new StatTypes(325, "WeaponDisallowedType"),
            new StatTypes(326, "WeaponDisallowedInstance"),
            new StatTypes(327, "Taboo"),
            new StatTypes(328, "Compulsion"),
            new StatTypes(329, "SkillDisabled"),
            new StatTypes(330, "ClanItemType"),
            new StatTypes(331, "ClanItemInstance"),
            new StatTypes(332, "DebuffFormula"),
            new StatTypes(333, "PvP_Rating", 1300),
            new StatTypes(334, "SavedXP", 0),
            new StatTypes(335, "DoorBlockTime"),
            new StatTypes(336, "OverrideTexture"),
            new StatTypes(337, "OverrideMaterial"),
            new StatTypes(338, "DeathReason"),
            new StatTypes(339, "DamageOverrideType"),
            new StatTypes(340, "BrainType"),
            new StatTypes(341, "XPBonus"),
            new StatTypes(342, "HealInterval"),
            new StatTypes(343, "HealDelta"),
            new StatTypes(344, "MonsterTexture"),
            new StatTypes(345, "HasAlwaysLootable"),
            new StatTypes(346, "TradeLimit"),
            new StatTypes(347, "FaceTexture"),
            new StatTypes(348, "SpecialCondition", 1),
            new StatTypes(349, "AutoAttackFlags", 5),
            new StatTypes(350, "NextXP", 1450),
            new StatTypes(351, "TeleportPauseMilliSeconds"),
            new StatTypes(352, "SISCap"),
            new StatTypes(353, "AnimSet"),
            new StatTypes(354, "AttackType"),
            new StatTypes(355, "NanoFocusLevel", 0),
            new StatTypes(356, "NPCHash"),
            new StatTypes(357, "CollisionRadius"),
            new StatTypes(358, "OuterRadius"),
            new StatTypes(359, "MonsterData", 0),
            new StatTypes(360, "MonsterScale"),
            new StatTypes(361, "HitEffectType"),
            new StatTypes(362, "ResurrectDest"),
            new StatTypes(363, "NanoInterval"),
            new StatTypes(364, "NanoDelta"),
            new StatTypes(365, "ReclaimItem"),
            new StatTypes(366, "GatherEffectType"),
            new StatTypes(367, "VisualBreed"),
            new StatTypes(368, "VisualProfession"),
            new StatTypes(369, "VisualSex"),
            new StatTypes(370, "RitualTargetInst"),
            new StatTypes(371, "SkillTimeOnSelectedTarget"),
            new StatTypes(372, "LastSaveXP", 0),
            new StatTypes(373, "ExtendedTime"),
            new StatTypes(374, "BurstRecharge"),
            new StatTypes(375, "FullAutoRecharge"),
            new StatTypes(376, "GatherAbstractAnim"),
            new StatTypes(377, "CastTargetAbstractAnim"),
            new StatTypes(378, "CastSelfAbstractAnim"),
            new StatTypes(379, "CriticalIncrease"),
            new StatTypes(380, "RangeIncreaserWeapon", 0),
            new StatTypes(381, "RangeIncreaserNF", 0),
            new StatTypes(382, "SkillLockModifier", 0),
            new StatTypes(383, "InterruptModifier"),
            new StatTypes(384, "ACGEntranceStyles"),
            new StatTypes(385, "ChanceOfBreakOnSpellAttack"),
            new StatTypes(386, "ChanceOfBreakOnDebuff"),
            new StatTypes(387, "DieAnim"),
            new StatTypes(388, "TowerType"),
            new StatTypes(389, "Expansion", 0),
            new StatTypes(390, "LowresMesh"),
            new StatTypes(391, "CriticalDecrease"),
            new StatTypes(392, "OldTimeExist"),
            new StatTypes(393, "ResistModifier"),
            new StatTypes(394, "ChestFlags"),
            new StatTypes(395, "PrimaryTemplateID"),
            new StatTypes(396, "NumberOfItems"),
            new StatTypes(397, "SelectedTargetType"),
            new StatTypes(398, "Corpse_Hash"),
            new StatTypes(399, "AmmoName"),
            new StatTypes(400, "Rotation"),
            new StatTypes(401, "CATAnim"),
            new StatTypes(402, "CATAnimFlags"),
            new StatTypes(403, "DisplayCATAnim"),
            new StatTypes(404, "DisplayCATMesh"),
            new StatTypes(405, "School"),
            new StatTypes(406, "NanoSpeed"),
            new StatTypes(407, "NanoPoints"),
            new StatTypes(408, "TrainSkill"),
            new StatTypes(409, "TrainSkillCost"),
            new StatTypes(410, "IsFightingMe"),
            new StatTypes(411, "NextFormula"),
            new StatTypes(412, "MultipleCount"),
            new StatTypes(413, "EffectType"),
            new StatTypes(414, "ImpactEffectType"),
            new StatTypes(415, "CorpseType"),
            new StatTypes(416, "CorpseInstance"),
            new StatTypes(417, "CorpseAnimKey"),
            new StatTypes(418, "UnarmedTemplateInstance", 0),
            new StatTypes(419, "TracerEffectType"),
            new StatTypes(420, "AmmoType"),
            new StatTypes(421, "CharRadius"),
            new StatTypes(422, "ChanceOfUse"),
            new StatTypes(423, "CurrentState", 0),
            new StatTypes(424, "ArmourType"),
            new StatTypes(425, "RestModifier"),
            new StatTypes(426, "BuyModifier"),
            new StatTypes(427, "SellModifier"),
            new StatTypes(428, "CastEffectType"),
            new StatTypes(429, "NPCBrainState"),
            new StatTypes(430, "WaitState", 2),
            new StatTypes(431, "SelectedTarget"),
            new StatTypes(432, "MissionBits4", 0),
            new StatTypes(433, "OwnerInstance"),
            new StatTypes(434, "CharState"),
            new StatTypes(435, "ReadOnly"),
            new StatTypes(436, "DamageType"),
            new StatTypes(437, "CollideCheckInterval"),
            new StatTypes(438, "PlayfieldType"),
            new StatTypes(439, "NPCCommand"),
            new StatTypes(440, "InitiativeType"),
            new StatTypes(441, "CharTmp1"),
            new StatTypes(442, "CharTmp2"),
            new StatTypes(443, "CharTmp3"),
            new StatTypes(444, "CharTmp4"),
            new StatTypes(445, "NPCCommandArg"),
            new StatTypes(446, "NameTemplate"),
            new StatTypes(447, "DesiredTargetDistance"),
            new StatTypes(448, "VicinityRange"),
            new StatTypes(449, "NPCIsSurrendering"),
            new StatTypes(450, "StateMachine"),
            new StatTypes(451, "NPCSurrenderInstance"),
            new StatTypes(452, "NPCHasPatrolList"),
            new StatTypes(453, "NPCVicinityChars"),
            new StatTypes(454, "ProximityRangeOutdoors"),
            new StatTypes(455, "NPCFamily"),
            new StatTypes(456, "CommandRange"),
            new StatTypes(457, "NPCHatelistSize"),
            new StatTypes(458, "NPCNumPets"),
            new StatTypes(459, "ODMinSizeAdd"),
            new StatTypes(460, "EffectRed"),
            new StatTypes(461, "EffectGreen"),
            new StatTypes(462, "EffectBlue"),
            new StatTypes(463, "ODMaxSizeAdd"),
            new StatTypes(464, "DurationModifier"),
            new StatTypes(465, "NPCCryForHelpRange"),
            new StatTypes(466, "LOSHeight"),
            new StatTypes(467, "PetReq1"),
            new StatTypes(468, "PetReq2"),
            new StatTypes(469, "PetReq3"),
            new StatTypes(470, "MapOptions", 0),
            new StatTypes(471, "MapAreaPart1", 0),
            new StatTypes(472, "MapAreaPart2", 0),
            new StatTypes(473, "FixtureFlags"),
            new StatTypes(474, "FallDamage"),
            new StatTypes(475, "ReflectReturnedProjectileAC", 0),
            new StatTypes(476, "ReflectReturnedMeleeAC", 0),
            new StatTypes(477, "ReflectReturnedEnergyAC", 0),
            new StatTypes(478, "ReflectReturnedChemicalAC", 0),
            new StatTypes(479, "ReflectReturnedRadiationAC", 0),
            new StatTypes(480, "ReflectReturnedColdAC", 0),
            new StatTypes(481, "ReflectReturnedNanoAC", 0),
            new StatTypes(482, "ReflectReturnedFireAC", 0),
            new StatTypes(483, "ReflectReturnedPoisonAC", 0),
            new StatTypes(484, "ProximityRangeIndoors"),
            new StatTypes(485, "PetReqVal1"),
            new StatTypes(486, "PetReqVal2"),
            new StatTypes(487, "PetReqVal3"),
            new StatTypes(488, "TargetFacing"),
            new StatTypes(489, "Backstab"),
            new StatTypes(490, "OriginatorType"),
            new StatTypes(491, "QuestInstance"),
            new StatTypes(492, "QuestIndex1"),
            new StatTypes(493, "QuestIndex2"),
            new StatTypes(494, "QuestIndex3"),
            new StatTypes(495, "QuestIndex4"),
            new StatTypes(496, "QuestIndex5"),
            new StatTypes(497, "QTDungeonInstance"),
            new StatTypes(498, "QTNumMonsters"),
            new StatTypes(499, "QTKilledMonsters"),
            new StatTypes(500, "AnimPos"),
            new StatTypes(501, "AnimPlay"),
            new StatTypes(502, "AnimSpeed"),
            new StatTypes(503, "QTKillNumMonsterID1"),
            new StatTypes(504, "QTKillNumMonsterCount1"),
            new StatTypes(505, "QTKillNumMonsterID2"),
            new StatTypes(506, "QTKillNumMonsterCount2"),
            new StatTypes(507, "QTKillNumMonsterID3"),
            new StatTypes(508, "QTKillNumMonsterCount3"),
            new StatTypes(509, "QuestIndex0"),
            new StatTypes(510, "QuestTimeout"),
            new StatTypes(511, "Tower_NPCHash"),
            new StatTypes(512, "PetType"),
            new StatTypes(513, "OnTowerCreation"),
            new StatTypes(514, "OwnedTowers"),
            new StatTypes(515, "TowerInstance"),
            new StatTypes(516, "AttackShield"),
            new StatTypes(517, "SpecialAttackShield"),
            new StatTypes(518, "NPCVicinityPlayers"),
            new StatTypes(519, "NPCUseFightModeRegenRate"),
            new StatTypes(520, "Rnd"),
            new StatTypes(521, "SocialStatus", 0),
            new StatTypes(522, "LastRnd"),
            new StatTypes(523, "ItemDelayCap"),
            new StatTypes(524, "RechargeDelayCap"),
            new StatTypes(525, "PercentRemainingHealth"),
            new StatTypes(526, "PercentRemainingNano"),
            new StatTypes(527, "TargetDistance"),
            new StatTypes(528, "TeamCloseness"),
            new StatTypes(529, "NumberOnHateList"),
            new StatTypes(530, "ConditionState"),
            new StatTypes(531, "ExpansionPlayfield"),
            new StatTypes(532, "ShadowBreed", 0),
            new StatTypes(533, "NPCFovStatus"),
            new StatTypes(534, "DudChance"),
            new StatTypes(535, "HealMultiplier"),
            new StatTypes(536, "NanoDamageMultiplier", 0),
            new StatTypes(537, "NanoVulnerability"),
            new StatTypes(538, "AmsCap"),
            new StatTypes(539, "ProcInitiative1"),
            new StatTypes(540, "ProcInitiative2"),
            new StatTypes(541, "ProcInitiative3"),
            new StatTypes(542, "ProcInitiative4"),
            new StatTypes(543, "FactionModifier"),
            new StatTypes(544, "MissionBits8", 0),
            new StatTypes(545, "MissionBits9", 0),
            new StatTypes(546, "StackingLine2"),
            new StatTypes(547, "StackingLine3"),
            new StatTypes(548, "StackingLine4"),
            new StatTypes(549, "StackingLine5"),
            new StatTypes(550, "StackingLine6"),
            new StatTypes(551, "StackingOrder"),
            new StatTypes(552, "ProcNano1"),
            new StatTypes(553, "ProcNano2"),
            new StatTypes(554, "ProcNano3"),
            new StatTypes(555, "ProcNano4"),
            new StatTypes(556, "ProcChance1"),
            new StatTypes(557, "ProcChance2"),
            new StatTypes(558, "ProcChance3"),
            new StatTypes(559, "ProcChance4"),
            new StatTypes(560, "OTArmedForces", 0),
            new StatTypes(561, "ClanSentinels", 0),
            new StatTypes(562, "OTMed"),
            new StatTypes(563, "ClanGaia", 0),
            new StatTypes(564, "OTTrans", 0),
            new StatTypes(565, "ClanVanguards", 0),
            new StatTypes(566, "GOS", 0),
            new StatTypes(567, "OTFollowers", 0),
            new StatTypes(568, "OTOperator", 0),
            new StatTypes(569, "OTUnredeemed", 0),
            new StatTypes(570, "ClanDevoted", 0),
            new StatTypes(571, "ClanConserver", 0),
            new StatTypes(572, "ClanRedeemed", 0),
            new StatTypes(573, "SK", 0),
            new StatTypes(574, "LastSK", 0),
            new StatTypes(575, "NextSK", 0),
            new StatTypes(576, "PlayerOptions", 0),
            new StatTypes(577, "LastPerkResetTime", 0),
            new StatTypes(578, "CurrentTime"),
            new StatTypes(579, "ShadowBreedTemplate", 0),
            new StatTypes(580, "NPCVicinityFamily"),
            new StatTypes(581, "NPCScriptAMSScale"),
            new StatTypes(582, "ApartmentsAllowed", 1),
            new StatTypes(583, "ApartmentsOwned", 0),
            new StatTypes(584, "ApartmentAccessCard"),
            new StatTypes(585, "MapAreaPart3", 0),
            new StatTypes(586, "MapAreaPart4", 0),
            new StatTypes(587, "NumberOfTeamMembers"),
            new StatTypes(588, "ActionCategory"),
            new StatTypes(589, "CurrentPlayfield"),
            new StatTypes(590, "DistrictNano"),
            new StatTypes(591, "DistrictNanoInterval"),
            new StatTypes(592, "UnsavedXP", 0),
            new StatTypes(593, "RegainXPPercentage", 0),
            new StatTypes(594, "TempSaveTeamID", 0),
            new StatTypes(595, "TempSavePlayfield", 0),
            new StatTypes(596, "TempSaveX", 0),
            new StatTypes(597, "TempSaveY", 0),
            new StatTypes(598, "ExtendedFlags"),
            new StatTypes(599, "ShopPrice"),
            new StatTypes(600, "NewbieHP"),
            new StatTypes(601, "HPLevelUp"),
            new StatTypes(602, "HPPerSkill"),
            new StatTypes(603, "NewbieNP"),
            new StatTypes(604, "NPLevelUp"),
            new StatTypes(605, "NPPerSkill"),
            new StatTypes(606, "MaxShopItems"),
            new StatTypes(607, "PlayerID"),
            new StatTypes(608, "ShopRent"),
            new StatTypes(609, "SynergyHash"),
            new StatTypes(610, "ShopFlags"),
            new StatTypes(611, "ShopLastUsed"),
            new StatTypes(612, "ShopType"),
            new StatTypes(613, "LockDownTime"),
            new StatTypes(614, "LeaderLockDownTime"),
            new StatTypes(615, "InvadersKilled", 0),
            new StatTypes(616, "KilledByInvaders", 0),
            new StatTypes(617, "MissionBits10", 0),
            new StatTypes(620, "HouseTemplate"),
            new StatTypes(621, "PercentFireDamage"),
            new StatTypes(622, "PercentColdDamage"),
            new StatTypes(623, "PercentMeleeDamage"),
            new StatTypes(624, "PercentProjectileDamage"),
            new StatTypes(625, "PercentPoisonDamage"),
            new StatTypes(626, "PercentRadiationDamage"),
            new StatTypes(627, "PercentEnergyDamage"),
            new StatTypes(628, "PercentChemicalDamage"),
            new StatTypes(629, "TotalDamage"),
            new StatTypes(630, "TrackProjectileDamage"),
            new StatTypes(631, "TrackMeleeDamage"),
            new StatTypes(632, "TrackEnergyDamage"),
            new StatTypes(633, "TrackChemicalDamage"),
            new StatTypes(634, "TrackRadiationDamage"),
            new StatTypes(635, "TrackColdDamage"),
            new StatTypes(636, "TrackPoisonDamage"),
            new StatTypes(637, "TrackFireDamage"),
            new StatTypes(638, "NPCSpellArg1"),
            new StatTypes(639, "NPCSpellRet1"),
            new StatTypes(640, "CityInstance"),
            new StatTypes(641, "DistanceToSpawnpoint"),
            new StatTypes(642, "CityTerminalRechargePercent"),
            new StatTypes(651, "AdvantageHash1"),
            new StatTypes(652, "AdvantageHash2"),
            new StatTypes(653, "AdvantageHash3"),
            new StatTypes(654, "AdvantageHash4"),
            new StatTypes(655, "AdvantageHash5"),
            new StatTypes(656, "ShopIndex"),
            new StatTypes(657, "ShopID"),
            new StatTypes(658, "IsVehicle"),
            new StatTypes(659, "DamageToNano"),
            new StatTypes(660, "AccountFlags"),
            new StatTypes(661, "DamageToNanoMultiplier"),
            new StatTypes(662, "MechData", 0),
            new StatTypes(664, "VehicleAC"),
            new StatTypes(665, "VehicleDamage"),
            new StatTypes(666, "VehicleHealth"),
            new StatTypes(667, "VehicleSpeed"),
            new StatTypes(668, "BattlestationSide", 0),
            new StatTypes(669, "VP", 0),
            new StatTypes(670, "BattlestationRep", 10),
            new StatTypes(671, "PetState"),
            new StatTypes(672, "PaidPoints", 0),
            new StatTypes(673, "VisualFlags", 31),
            new StatTypes(674, "PVPDuelKills", 0),
            new StatTypes(675, "PVPDuelDeaths", 0),
            new StatTypes(676, "PVPProfessionDuelKills", 0),
            new StatTypes(677, "PVPProfessionDuelDeaths", 0),
            new StatTypes(678, "PVPRankedSoloKills", 0),
            new StatTypes(679, "PVPRankedSoloDeaths", 0),
            new StatTypes(680, "PVPRankedTeamKills", 0),
            new StatTypes(681, "PVPRankedTeamDeaths", 0),
            new StatTypes(682, "PVPSoloScore", 0),
            new StatTypes(683, "PVPTeamScore", 0),
            new StatTypes(684, "PVPDuelScore", 0),
            new StatTypes(700, "ACGItemSeed"),
            new StatTypes(701, "ACGItemLevel"),
            new StatTypes(702, "ACGItemTemplateID"),
            new StatTypes(703, "ACGItemTemplateID2"),
            new StatTypes(704, "ACGItemCategoryID"),
            new StatTypes(768, "HasKnubotData"),
            new StatTypes(800, "QuestBoothDifficulty"),
            new StatTypes(801, "QuestASMinimumRange"),
            new StatTypes(802, "QuestASMaximumRange"),
            new StatTypes(888, "VisualLODLevel"),
            new StatTypes(889, "TargetDistanceChange"),
            new StatTypes(900, "TideRequiredDynelID"),
            new StatTypes(999, "StreamCheckMagic"),
            new StatTypes(1001, "Type"),
            new StatTypes(1002, "Instance"),
            new StatTypes(1234567890, "NoStatValue")
        };
        #endregion

        /// <summary>
        /// 
        /// </summary>
        /// <param name="statName"></param>
        /// <returns></returns>
        public static int GetStatId(string statName)
        {
            if (statName == string.Empty)
                return 0;

            try
            {
                // Are we passed a StatId? If so, return it as an int

                int statId = int.Parse(statName);

                if (statId > 0)
                    return statId;
            }
            catch (Exception)
            {
            }

            foreach (StatTypes stat in stats)
            {
                if (stat.statName.ToLower() == statName.ToLower())
                    return stat.statId;
            }

            Console.WriteLine("Unknown statName: " + statName);

            return 0;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="statId"></param>
        /// <returns></returns>
        public static string GetStatName(int statId)
        {
            foreach (StatTypes stat in stats)
            {
                if (stat.statId == statId)
                    return stat.statName;
            }

            Console.Write("Unknown statId: " + statId);

            return "UnknownStat#" + statId;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="statId"></param>
        /// <returns></returns>
        public static int GetDefaultValue(int statId)
        {
            foreach (StatTypes stat in stats)
            {
                if (stat.statId == statId)
                    return stat.defaultValue;
            }

            Console.WriteLine("Using generic DefaultValue for statId " + statId);

            // Generic default value
            return 1234567890;
        }
    }

    /// <summary>
    /// 
    /// </summary>
    class CharacterStat
    {
        public int statId;
        public int statValue;

        /// <summary>
        /// 
        /// </summary>
        /// <param name="statId"></param>
        /// <param name="statValue"></param>
        public CharacterStat(int statId, int statValue)
        {
            this.statId = statId;
            this.statValue = statValue;
        }
    }

    /// <summary>
    /// 
    /// </summary>
    public class CharacterStats
    {
        #region MySQL
        /// <summary>
        /// MySQL Wrapper
        /// </summary>
        public MySqlWrapper mySql = new MySqlWrapper();

        #endregion

        List<CharacterStat> statsTable = new List<CharacterStat>();

        /// <summary>
        /// 
        /// </summary>
        /// <param name="character"></param>
        /// <returns></returns>
        public bool ReadStats(Character character)
        {
            int numberOfStats = 0;

            mySql.MySqlRead("SELECT `Stat`, `Value` FROM `character_stats` WHERE `ID` = " + character.characterId + ";");

            while (mySql.myreader.Read())
            {
                int statId = mySql.myreader.GetInt32(0);

                // Expansion, AccountFlags and PlayerID are obtained from the login table
                // Technically this should never happen, but if it did, it would be a pain to debug, so better safe than sorry...
                if ((statId == 389) || (statId == 660) || (statId == 607))
                    continue;

                if (statId == 10) // ProfessionLevel is based off Level
                    continue;

                if (statId == 215) // GmLevel is based off GM flag in Login table
                    continue;

                // Type and Instance - same deal as above, shouldn't happen, but just in case...
                if (statId == 1001)
                    continue;
                if (statId == 1002)
                    continue;

                statsTable.Add(new CharacterStat(statId, mySql.myreader.GetInt32(1)));

                numberOfStats++;
            }

            mySql.myreader.Close();

            mySql.mcc.Close();

            mySql.MySqlRead("SELECT `ID`, `Expansions`, `AccountFlags`, `GM` FROM `login` WHERE `Username` = (SELECT `Username` FROM `characters` WHERE `ID` = " + character.characterId + ");");

            if (mySql.myreader.Read())
            {
                // Stat 607 is PlayerID
                statsTable.Add(new CharacterStat(607, mySql.myreader.GetInt32(0)));

                // Stat 389 is Expansion
                statsTable.Add(new CharacterStat(389, mySql.myreader.GetInt32(1)));

                // Stat 660 is AccountFlags
                statsTable.Add(new CharacterStat(660, mySql.myreader.GetInt32(2)));

                // Stat 215 is GmLevel
                statsTable.Add(new CharacterStat(215, mySql.myreader.GetInt32(3)));
            }
            else
            {
                Console.WriteLine("Unable to read login table data for characterId " + character.characterId);
            }

            mySql.myreader.Close();

            mySql.mcc.Close();

            statsTable.Add(new CharacterStat(10, Math.Min(200, GetStat(54)))); // ProfessionLevel(10) based off Level(54) capped at 200
            statsTable.Add(new CharacterStat(1001, 50000)); // Type
            statsTable.Add(new CharacterStat(1002, character.characterId)); // Instance

            return numberOfStats > 0;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="character"></param>
        /// <returns></returns>
        public bool WriteStats(Character character)
        {
            int numberOfStats = 0;
            string sql = string.Empty;
            string sqlUpdatedStats = string.Empty;
            string startSqlValue = "(" + character.characterId + ", ";

            sql += "REPLACE INTO `character_stats` (`ID`, `Stat`, `Value`) VALUES ";

            foreach (CharacterStat stat in statsTable)
            {
                if ((stat.statId == 1234567890) || (stat.statValue == 1234567890)) // No point saving default value stats
                    continue;

                if ((stat.statId == 389) || (stat.statId == 660) || (stat.statId == 607)) // Expansion, AccountFlags and PlayerID are obtained from the login table
                    continue;

                if (stat.statId == 10) // ProfessionLevel is based off Level
                    continue;

                if (stat.statId == 215) // GmLevel is based off GM flag in Login table
                    continue;

                if ((stat.statId == 1001) || (stat.statId == 1002)) // Type and Instance
                    continue;

                if (stat.statValue == StatsList.GetDefaultValue(stat.statId)) // No point saving default values
                    continue;

                if (numberOfStats > 0)
                    sql += ",";

                sql += startSqlValue + stat.statId + ", " + stat.statValue + ")";

                sqlUpdatedStats += " AND `Stat` != " + stat.statId;

                numberOfStats++;
            }

            sql += ";";

            mySql.MySqlDelete("DELETE FROM `character_stats` WHERE `ID` = " + character.characterId + sqlUpdatedStats + ";");
            mySql.MySqlInsert(sql);

            return numberOfStats > 0;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="statId"></param>
        /// <returns></returns>
        public int GetStat(int statId)
        {
            foreach (CharacterStat stat in statsTable)
            {
                if (stat.statId == statId)
                    return stat.statValue;
            }

            // Character does not have the stat set, lets find the default stat value for this then
            return StatsList.GetDefaultValue(statId);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="statName"></param>
        /// <returns></returns>
        public int GetStat(string statName)
        {
            return GetStat(StatsList.GetStatId(statName));
        }

        // Returns true if stat already existed, false if stat had to be added to the list
        /// <summary>
        /// 
        /// </summary>
        /// <param name="statId"></param>
        /// <param name="statValue"></param>
        /// <returns></returns>
        public bool SetStat(int statId, int statValue)
        {
            foreach (CharacterStat stat in statsTable)
            {
                if (stat.statId == statId)
                {
                    stat.statValue = statValue;

                    return true;
                }
            }

            statsTable.Add(new CharacterStat(statId, statValue));

            return false;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="statName"></param>
        /// <param name="statValue"></param>
        /// <returns></returns>
        public bool SetStat(string statName, int statValue)
        {
            return SetStat(StatsList.GetStatId(statName), statValue);
        }
    }
}
